<!--秒杀-->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="活动名称" prop="lang">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入活动名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开始时间" prop="startTime">
        <el-date-picker placeholder="选择时间" type="datetime" value-format="timestamp" v-model="queryParams.startTime"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="endTime">
        <el-date-picker placeholder="选择时间" type="datetime" value-format="timestamp" v-model="queryParams.endTime"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['car:vocabulary:add']"
        >新建活动</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <div class="my-tabs">
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="全部" name="0">

        </el-tab-pane>
        <el-tab-pane label="未开始" name="1">

        </el-tab-pane>
        <el-tab-pane label="进行中" name="2">

        </el-tab-pane>
        <el-tab-pane label="已结束" name="3">

        </el-tab-pane>
      </el-tabs>
    </div>
    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="活动名称" align="left" prop="name" width="160" :show-overflow-tooltip="true"/>
      <!--      <el-table-column label="退货原因" align="center" prop="idea" width="160" :show-overflow-tooltip="true"/>-->
      <el-table-column label="开始时间" align="center" prop="startTime" width="160" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          {{ parseTime(scope.row.startTime, '{y}-{m}-{d} {h}:{i}:{s}') }}
        </template>
      </el-table-column>
      <el-table-column label="结束时间" align="center" prop="endTime" width="160" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          {{ parseTime(scope.row.endTime, '{y}-{m}-{d} {h}:{i}:{s}') }}
        </template>
      </el-table-column>
      <el-table-column label="订单实付金额" align="center" prop="orderMoneys" width="160" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          {{$yun.priceFormatter(scope.row.orderMoneys) }}
        </template>
      </el-table-column>
      <el-table-column label="付款订单数" align="center" prop="orderNum" width="160" :show-overflow-tooltip="true"/>
      <el-table-column label="付款人数" align="center" prop="userNum" width="160" :show-overflow-tooltip="true"/>
      <el-table-column label="适用网店" align="center" prop="shopType" width="160" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.activity_store_type" :value="scope.row.shopType"></dict-tag>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status" width="160" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <!--          todo 标签没有样式-->
          <dict-tag :options="dict.type.seckill_status" :value="scope.row.status"></dict-tag>
          <!--          <dict-tag :options="dict.type.sign_status" :value="scope.row.sign"></dict-tag>-->
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="160" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          {{ parseTime(scope.row.createTime, '{m}/{d}/{y}') }}
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="220">
        <template slot-scope="scope">
         <div>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="$router.push(`/activity/addEditSeckill?id=${scope.row.id}`)"
            >编辑
            </el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="$router.push(`/activity/addEditSeckill?id=${scope.row.id}&type=copy`)"
            >复制
            </el-button>
            <el-button
              v-if="scope.row.status == 2"
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleEnd(scope.row)"
            >立即结束
            </el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.current"
      :limit.sync="queryParams.size"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  list,
  endActivity
} from '@/api/activity/seckill'
import Template from '@/views/setting/template/index.vue'
import { passAudit } from '@/api/live/liveAudit'
import DateRangePicker from '@/components/DateRangePicker/index.vue'
import { delAdvertisement } from '@/api/advertisement/indexhAdvertisement'

export default {
  name: 'seckill',
  components: { DateRangePicker, Template },
  dicts: ['activity_store_type', 'seckill_status'],
  data() {
    return {
      showSearch:true,
      activeName: '0',
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      dataList: [],
      // 弹出层标题
      // 查询参数
      queryParams: {
        current: 1,
        size: 10
      },
    }
  },
  created() {
    this.getList()
  },
  methods: {
    handleClick(tab, event) {
      this.queryParams.current = 1
      this.getList();
    },
    /** 查询退货申请列表 */
    getList() {
      this.loading = true
      list({ ...this.queryParams,status:this.activeName }).then(response => {
        this.dataList = response.data.records
        this.total = response.data.total
        this.loading = false
      })
    },
    /** 编辑 */
    handleDetails() {
      this.$router.push('/activity/addEditSeckill',);
    },
    /** 复制 */
    handleCopy() {

    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.current = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        current: 1,
        size: 10
      }
      this.handleQuery()
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push('/activity/addEditSeckill')
    },
    /** 结束按钮操作 */
    handleEnd(row) {
      this.$modal.confirm('是否确认立即结束秒杀活动？').then(function() {
        return endActivity( row.id )
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('已成功结束！')
      }).catch(() => {
      })
    },
  }
}
</script>
